<?php

namespace App\Exports;

use App\Http\Controllers\Attendance\AttendanceBusReportController;
use Maatwebsite\Excel\Concerns\FromArray;

class AttendanceBusExport implements FromArray
{
    public $month;

    public function __construct($month)
    {
        $this->month = $month;
    }

    public function array(): array
    {
        $params = [];
        $params['startDate'] = date('Y-m-01', strtotime($this->month));
        $params['endDate'] = date('Y-m-t', strtotime($this->month));

        $attendanceBus = new AttendanceBusReportController();

        $data = $attendanceBus->getAttendanceData($params)->orderBy('line')->get()->toArray();

        $data = $attendanceBus->transData($data, $params);

        return [
            ['车牌号', '线路', '小计', '加班', '修车', '停运', '晚上加班'],
            $data,
        ];
    }
}
